package org.itboys.rpc.service.category;

import java.util.List;

import org.itboys.ResultHolder;
import org.itboys.dto.Category;
import org.itboys.dto.base.Result;
import org.itboys.product.entity.ProductCategory;
import org.itboys.product.service.ProductCategoryService;
import org.itboys.rpc.service.BaseRpcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;

/**
 * 商品分类相关
 */
@Service
public class RpcProductCategoryService extends BaseRpcService {
	
	@Autowired
	private ProductCategoryService productCategoryService;

	/**
	 * 获取所有的分类
	 * 备注：建材标局只有一级分类  所以获取的所有分类，其实只有父类
	 * @return
	 */
	public Result<List<Category>> getAllCategory(){
		List<ProductCategory> pcList = productCategoryService.getRootCategory();
		List<Category> cList = null;
		if(!pcList.isEmpty()){
			cList = Lists.newArrayListWithExpectedSize(pcList.size());
			for(ProductCategory pc : pcList){
				Category c= new Category();
				c.setId(pc.getId());
				c.setName(pc.getName());
				c.setLogo(pc.getLogo());
				cList.add(c);
			}
		}
		return ResultHolder.getSuccessResult(cList);
	}
}
